#include "contactform.h"

#include "ui_contactform.h"
#include <CommonUtils.h>

ContactForm::ContactForm(WindowManager* manager, QWidget* parent) : QWidget(parent),
                                                                    windowManager(*manager),
                                                                    ui(new Ui::ContactForm) {
    ui->setupUi(this);
    init();
}

ContactForm::~ContactForm() {
    delete ui;
}

void ContactForm::init() {
    CommonUtils::loadStyleSheet(this, "contactform");
    friendListForm = new FriendListForm(windowManager, ui->stackedWidget);
    roomListForm   = new RoomListForm(windowManager, ui->stackedWidget);

    ui->stackedWidget->addWidget(friendListForm);
    ui->stackedWidget->setCurrentWidget(friendListForm);
    ui->stackedWidget->addWidget(roomListForm);

    connect(ui->btn_friends, &QPushButton::clicked, [this](bool checked) {
        if (checked) {
            ui->stackedWidget->setCurrentWidget(friendListForm);
        }
    });
    connect(ui->btn_rooms, &QPushButton::clicked, [this](bool checked) {
        if (checked) {
            ui->stackedWidget->setCurrentWidget(roomListForm);
        }
    });
    connect(friendListForm, SIGNAL(signalToggle()), SLOT(onSignalToggle()));
    connect(roomListForm, SIGNAL(signalToggle()), SLOT(onSignalToggle()));


    ui->btn_friends->setChecked(true);
}

void ContactForm::onSignalToggle() {
    emit signalToggle();
}
